package com.example.manager.web;

import com.example.common.Ov.UserOv;
import com.example.common.entity.Const;
import com.example.common.entity.Rsp;
import com.example.common.pojo.Admin;
import com.example.common.pojo.User;
import com.example.common.util.JWTUtil;
import com.example.manager.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLOutput;

@RestController
@RequestMapping("user")
public class AdminController {
    @Autowired
    AdminService adminService;

    @PostMapping("login")
    public Rsp login(@RequestBody Admin admin) {
        Rsp login = adminService.login(admin);
        return login;
    }

    @GetMapping("getUserInfo")
    public Rsp getUserInfo(@RequestHeader("token") String token) {

        UserOv userOv = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        Integer id = userOv.getId();
        Rsp userInfo = adminService.getUserInfo(id);
        return userInfo;


    }

    //登出
    @PostMapping("logout")
    public Rsp logout(String token) {
        return new Rsp(20000, "登出成功");
    }
}
